MySQL中使用外键[FOREIGN KEY]

Categories: Database; Tagged with: ; @ November 6th, 2008 23:25

SQL语言:

CREATE TABLE Class (
Class_ID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255)
) type=innodb;

CREATE TABLE Student(
Student_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255),
c_ID INT UNSIGNED NOT NULL,
FOREIGN KEY(c_ID) REFERENCES Class(Class_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);

逻辑图:
image

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.